//
//  SubjectView.m
//  Tour
//
//  Created by hesiyao on 16/3/8.
//  Copyright © 2016年 张中烨. All rights reserved.
//

#import "SubjectView.h"

@implementation SubjectView

//- (instancetype)initWithFrame:(CGRect)frame
//{
//    self = [super initWithFrame:frame];
//    if (self) {
//        [self createSubviews];
//    }
//    return self;
//}

-(id)initWithFrame:(CGRect)frame urlStrArr:(NSMutableArray *)urlStrArr
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubviews];
        self.urlStrArr = urlStrArr;
    }
    return self;
}

//创建视图
- (void)createSubviews
{
    // 题目:发现下一站
    self.titleLabel = [[BaseLabel alloc] initWithFrame:CGRectMake(20, 0, self.frame.size.width, self.frame.size.height / 10)];
    _titleLabel.textColor = [UIColor grayColor];
    _titleLabel.font = [UIFont systemFontOfSize:15];
    _titleLabel.text = @"发现下一站";
    [_titleLabel NightWithType:UIViewColorTypeNormal];
    [self addSubview:_titleLabel];
    
    //第一个大图片
    self.bigImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, _titleLabel.frame.origin.y + _titleLabel.frame.size.height, self.frame.size.width - 10, self.frame.size.height / 2.5)];
    //按屏幕剪切
    _bigImageView.contentMode = UIViewContentModeScaleAspectFill;
    _bigImageView.clipsToBounds = YES;
    [self addSubview:_bigImageView];
    // 添加点击方法
    UITapGestureRecognizer *bigTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(BigTapAction)];
    [_bigImageView addGestureRecognizer:bigTap];
    _bigImageView.userInteractionEnabled = YES;
    
    
    //第二行左边的图片
    self.leftImageView = [[UIImageView alloc] initWithFrame:CGRectMake(5, _bigImageView.frame.origin.y + _bigImageView.frame.size.height + 5, (self.frame.size.width - 15) / 2, self.frame.size.height / 3.5)];
    _leftImageView.contentMode = UIViewContentModeScaleAspectFill;
    _leftImageView.clipsToBounds = YES;
    [self addSubview:_leftImageView];
    // 添加点击方法
    UITapGestureRecognizer *leftTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(LeftTapAction)];
    [_leftImageView addGestureRecognizer:leftTap];
    _leftImageView.userInteractionEnabled = YES;
    
    //第二行右边的图
    self.rightImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10 + _leftImageView.frame.size.width, _leftImageView.frame.origin.y, _leftImageView.frame.size.width, _leftImageView.frame.size.height)];
    _rightImageView.contentMode = UIViewContentModeScaleAspectFill;
    _rightImageView.clipsToBounds = YES;
    [self addSubview:_rightImageView];// 添加点击方法
    UITapGestureRecognizer *rightTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(RightTapAction)];
    [_rightImageView addGestureRecognizer:rightTap];
    _rightImageView.userInteractionEnabled = YES;
    
    //更多专题按钮
    self.moreSubjectButton = [UIButton buttonWithType:UIButtonTypeSystem];
    _moreSubjectButton.frame = CGRectMake(0, _leftImageView.frame.origin.y +_leftImageView.frame.size.height + 5, self.frame.size.width, _titleLabel.frame.size.height);
    [_moreSubjectButton setTitle:@"查看更多精彩专题>" forState:UIControlStateNormal];
    [_moreSubjectButton NightWithType:UIViewColorTypeNormal];
    [self addSubview:_moreSubjectButton];
    
    //看热门游记
    self.hotTravelNotes = [[BaseLabel alloc] initWithFrame:CGRectMake(20, _moreSubjectButton.frame.origin.y + _moreSubjectButton.frame.size.height, _titleLabel.frame.size.width, self.frame.size.height - _bigImageView.frame.size.height - _titleLabel.frame.size.height - _leftImageView.frame.size.height - _moreSubjectButton.frame.size.height - 10 )];
    _hotTravelNotes.textColor = [UIColor grayColor];
    _hotTravelNotes.font = [UIFont systemFontOfSize:15];
    _hotTravelNotes.text = @"看热门游记";
    [_hotTravelNotes NightWithType:UIViewColorTypeNormal];
    [self addSubview:_hotTravelNotes];
}

- (void)BigTapAction
{
    NSString *urlStr = _urlStrArr[0];
    [self.delegate pushBigWebWithUrl:urlStr];
}

- (void)LeftTapAction
{
    NSString *urlStr = _urlStrArr[1];
    [self.delegate pushBigWebWithUrl:urlStr];
}

- (void)RightTapAction
{
    NSString *urlStr = _urlStrArr[2];
    [self.delegate pushBigWebWithUrl:urlStr];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
